Attribute VB_Name = "modODBCCDI"
'---------------------------------------------------------------------------------------
'Module     : modODBC
'Author     : Chris Elwell
'Purpose    : This is an example of a CIC integration module. This is for demostration
'           purposes only. You must write the code required to get/writeback data from/to
'           your customer's data source.
'
'           This example uses the AddrVerify.mdb. A DSN is setup as AddrVerify.
'           Regardless of the integration method, CICs must have a module that contains
'           specific sub routines. All of these subs/functions listed below must exist
'           as they are called from the main program.
'
'           Public Function GetData(ByVal strKey As String) As Boolean - this routine is
'               called when the Order ID field loses focus. This is where you would code to
'               get order data from a customer and populate the screen fields. You can create
'               and call as many support routines as necessary. Also, this routine should
'               return a boolean True if getting the order data was succesful and a boolean
'               False if it was not.
'           Public Function GetPickupData(ByVal strKey As String) As Boolean - this routine is
'               called when the Order ID on the FedEx Returns for field loses focus.
'               This operates the same as GetData above but for use obtaining the Pickup From
'               address info on the Call Tag/Express Tag form.
'           Public Sub WriteReply() - this is called after a successful shipment. A typical
'               use would be to write FXRS reply data back to a customer's system, but can be
'               used for anything that you want to have happen after a package is shipped.
'           Public Sub WriteReturnReply() - this is called after a successful Return Label
'               shipment. Use this to write FXRS reply data back to the customer's system.
'               This is called on both regular and online return labels.
'           Public Sub WriteBOLReply() - this is called after a successful FedEx Freight BOL shipment.
'           Public Sub WriteBatchEditReply() - this is called after a successful Batch Error
'           Edit shipment.
'           Public Sub WriteTagReply() - this is called after a successful Call/Express Tag
'           Public Sub WriteCancelTagReply() - this is called after a Call/Express Tag is Canceled
'           Public Sub WriteError() - this is called after an error is returned from FXRS.
'           Public Sub WriteDelete(ByVal strTracking As String) - this is called after a
'               package is successfully deleted.
'           Public Sub WriteReturnDelete(ByVal strTracking As String) - this is called after
'               a successful Return Label delete. Use this to write FXRS reply data back to
'               the customer's system. This is called on both regular and online return labels.
'           Public Sub AfterClose() - this is called after FXRS is closed.
'           Public Sub AfterLocationChange() - this is called after the Current Location is changed
'               on frmShip.
'           Public Sub BeforeClose() - this is called just before an FXRS close transaction
'               is sent and must return a boolean True for the Close to proceed.
'           Public Function BeforeShip() - Return TRUE to continue shipment, False to cancel.
'           Public Sub Initialize() - this is called once on program execution.
'UPDATED    Public Function BeforeBatch() - Return TRUE to process a batch file.
'UPDATED    Public Function BeforeBatchShip() - Return TRUE to process an individual batch transaction.
'           Public Sub AfterBatchShip() - this is called after each shipment in batch processing.
'           Public Sub AfterBatch() - this is called after a completed batch shipment.
'           Public Sub AfterAddrLookup() - this is called after cboCustID, cboContact, and
'                                          cboCompany lose focus
'           Public Sub AfterDeptLostFocus() - this is called after cboDept or f38 loses focus.
'           Public Sub AfterAddrVerifyUpdate() - this is called after the Update button is
'                                            clicked on the Verify Address form.
'           Public Sub AfterAddrVerify(ByVal intStatusCode As Integer) - this is called after
'               Address Verification. The status code indicates 1 address verified, 2 there was
'               a soft error returned, 3 there was a hard error returned.
'NEW        Public Function BuildCustomSPLabel(ByVal strLabel As String) As String - this is called
'               from BuildSPEPLLabel and BuildSPZPLLabel in modSmartPost. This allow CICs to create
'               custom SmartPost labels in either ZPL or EPL.
'---------------------------------------------------------------------------------------
Option Explicit

#If CDI Then

Dim m_CNIn As ADODB.Connection
Dim m_CNOut As ADODB.Connection
Dim m_rsOrder As ADODB.Recordset
Dim m_rsExt As ADODB.Recordset
Dim m_rsProduct As ADODB.Recordset
Dim m_strLine As String
Dim m_str37 As String
'

'---------------------------------------------------------------------------------------
' Procedure : AfterBatchShip()
' DateTime  : 10/28/2005
' Purpose   : REQUIRED SUB. Called just after a batch transaction has been processed.
'---------------------------------------------------------------------------------------
'
Public Sub AfterBatchShip()

End Sub
'---------------------------------------------------------------------------------------
' Procedure : AfterBatch()
' DateTime  : 4/6/2005
' Purpose   : REQUIRED SUB. Can be used as hook to call routines to be executed after
'             a batch shipment has been completed.
'---------------------------------------------------------------------------------------
'
Public Sub AfterBatch()

End Sub
'---------------------------------------------------------------------------------------
' Procedure : AfterAddrLookup()
' DateTime  : 2/21/2005
' Purpose   : REQUIRED SUB. Can be used as hook to call routines to be executed after
'             cboCustID, cboContact, or cboCompany loses focus.
'---------------------------------------------------------------------------------------
'
Public Sub AfterAddrLookup()
    frmShip.f25.SetFocus
End Sub
'---------------------------------------------------------------------------------------
' Procedure : AfterDeptLostFocus()
' DateTime  : 2/21/2005
' Purpose   : REQUIRED SUB. Can be used as hook to call routines to be executed after
'             f38 loses focus.
'---------------------------------------------------------------------------------------
'
Public Sub AfterDeptLostFocus()

    On Error Resume Next
    g_clsReg.SetRegistryValue "Carry_f38", frmShip.f38, REG_SZ

End Sub
'---------------------------------------------------------------------------------------
' Procedure : AfterAddrVerifyUpdate()
' DateTime  : 9/13/2005
' Purpose   : REQUIRED SUB. Can be used as hook to call routines to be executed after
'             an address has been updated on the Ship form.
'---------------------------------------------------------------------------------------
'
Public Sub AfterAddrVerifyUpdate()

End Sub
'---------------------------------------------------------------------------------------
' Procedure : AfterLocationChange()
' DateTime  : 3/06/2006
' Purpose   : REQUIRED SUB. Can be used as hook to call routines to be executed after
'             the shipping Location has been changed on the Ship form.
'---------------------------------------------------------------------------------------
'
Public Sub AfterLocationChange()

End Sub
'---------------------------------------------------------------------------------------
' Procedure : AfterAddrVerify()
' DateTime  : 5/12/2006
' Purpose   : REQUIRED SUB. Can be used as hook to call routines to be executed after
'             Address Verification. Three possible status codes are passed. See comments
'             below.
'---------------------------------------------------------------------------------------
'
Public Sub AfterAddrVerify(ByVal intStatusCode As Integer)

    Select Case intStatusCode
        'Address is verfified
        Case 1

        'Soft error
        Case 2

        'Hard error
        Case 3

    End Select

End Sub
'

' 2011-07-10, JFW, New interface to clear DG disclaimer automatically.
Public Function AfterDGDisclaimer() As Boolean
    AfterDGDisclaimer = False
End Function
'

'---------------------------------------------------------------------------------------
' Procedure : AfterLoadServices()
' DateTime  : 5/17/2011
' Purpose   : Remove or add custom services.
' 2011-05-17, JFW, New for Scapa
'---------------------------------------------------------------------------------------
'
Public Sub AfterLoadServices(c1 As ComboBox)

End Sub
'

'---------------------------------------------------------------------------------------
' Procedure : AfterLostFocus()
' DateTime  : 2/21/2005
' Purpose   : REQUIRED SUB. Can be used as hook to call routines to be executed after
'             cboDept or f38 loses focus.
'---------------------------------------------------------------------------------------
'
Public Sub AfterLostFocus(c1 As Control)
    
    On Error GoTo EH
    
    Dim rsQuery As String
    Dim grdCommodities As DataGrid
    Dim i As Long
    Dim j As Long
    Static rsCommodity As ADODB.Recordset
    Dim strCommodityID As String
    
    If c1.name = "f15" Then
        Debug.Assert False
    End If
    If c1.name = "f38" Then
        If frmShip.f38.ListIndex >= 0 Then
            g_clsReg.SetRegistryValue "Carry_f38", frmShip.f38, REG_SZ
        End If
    End If
    If c1.name = "f50" Then
        If c1.ListIndex >= 0 Then
            g_clsReg.SetRegistryValue "Carry_f50", Left(c1.Text, 2), REG_SZ
            If frmShip.chkIntlIPD.Value = 1 And Left(frmShip.f50.Text, 2) <> "US" Then
                frmShip.chkIntlIPD.Value = 0
                Call frmShip.EnableDisableIPD(False)
            End If
            If frmShip.chkIntlIPD.Value = 0 Or Left(frmShip.f50.Text, 2) <> "US" Then
                If Right(frmShip.cboLocationName(0).Text, 3) = "IPD" Then
                    frmShip.SetLocationName Left(frmShip.cboLocationName(0).Text, (Len(frmShip.cboLocationName(0).Text) - 3))
                    Call AfterLostFocus(frmShip.cboLocationName(0))
                    Call frmShip.EnableDisableIPD(frmShip.chkIntlIPD) ' Again on location change
                End If
            End If
        End If
    End If
    If c1.name = "f75" Then
        If frmShip.f75.ListIndex >= 0 Then
            g_clsReg.SetRegistryValue "Carry_f75", frmShip.f75, REG_SZ
        End If
    End If
    If c1.name = "f1273" Then
        If frmShip.f1273.ListIndex >= 0 Then
            g_clsReg.SetRegistryValue "Carry_f1273", Left(frmShip.f1273.Text, 2), REG_SZ
        End If
    End If
    If c1.name = "f1274" Then
        If frmShip.f1274.ListIndex >= 0 Then
            ' Don't carry the IPD service type, we carry the IPD flag
            If Left(frmShip.f1274.Text, 2) <> "18" _
            And Left(frmShip.f1274.Text, 3) <> "111" Then
                g_clsReg.SetRegistryValue "Carry_f1274", Trim(Left(frmShip.f1274.Text, 3)), REG_SZ
            End If
        End If
    End If
    If c1.name = "f1275" Then
    If QuoteTrim(c1.Text) <> "" Then
        i = InStr(1, frmShip.f79.Text, "; Part")
        If i <> 0 Then
            j = InStr(i + 11, frmShip.f79.Text, ";")
            If j > 0 Then
                frmShip.f79.Text = Left(frmShip.f79.Text, i - 1) & Mid(frmShip.f79.Text, j, 255)
            Else
                frmShip.f79.Text = Left(frmShip.f79.Text, i - 1)
            End If
        End If
        frmShip.f79.Text = frmShip.f79.Text & "; Part " & frmShip.f1275.Text
    End If
    End If
    If c1.name = "grdCommodities" Then
        Set grdCommodities = c1
        If grdCommodities.Columns("Workstation").Text = "" Then
            grdCommodities.Columns("Workstation").Text = g_strComputerName
        End If
        
        ' Change to CommodityID or Cntry of Mfg
        If grdCommodities.Columns("CommodityID").Text <> "" _
        And grdCommodities.Columns("Cntry of Mfg").Text <> "" _
        And Len(grdCommodities.Columns("Cntry of Mfg").Text) = 2 _
        And (grdCommodities.Columns(grdCommodities.col).Caption = "Cntry of Mfg" _
        Or grdCommodities.Columns(grdCommodities.col).Caption = "CommodityID") Then
            If Not rsCommodity Is Nothing Then
                If rsCommodity.State = adStateOpen Then rsCommodity.Close
            Else
                Set rsCommodity = New ADODB.Recordset
            End If
            
            rsQuery = "SELECT * FROM Commodity WHERE CommodityID = '" _
                & grdCommodities.Columns("CommodityID").Text & " " _
                & grdCommodities.Columns("Cntry of Mfg").Text & "'"
            rsCommodity.Open rsQuery, g_connFSMSClient, adOpenKeyset, adLockOptimistic
            
            ' Maybe remove Country from the CommodityID and try again
            If rsCommodity.EOF Then
                rsCommodity.Close
                rsQuery = "SELECT * FROM Commodity WHERE CommodityID = '" _
                    & Left(grdCommodities.Columns("CommodityID").Text, Len(grdCommodities.Columns("CommodityID").Text) - 3) & " " _
                    & grdCommodities.Columns("Cntry of Mfg").Text & "'"
            
                rsCommodity.Open rsQuery, g_connFSMSClient, adOpenKeyset, adLockOptimistic
            End If
            
            If Not rsCommodity.EOF Then
                grdCommodities.Columns("CommodityID").Text = rsCommodity("CommodityID") & ""
                grdCommodities.Columns("Description").Text = rsCommodity("g_str79") _
                    & "; Part " & grdCommodities.Columns("CommodityID").Text & " " _
                    & grdCommodities.Columns("Part Number").Text
                grdCommodities.Columns("Harmonized Code").Text = rsCommodity("g_str81") & ""
                grdCommodities.Columns("MID").Text = rsCommodity("MID") & ""
                grdCommodities.Columns("Document1").Text = rsCommodity("Document1") & ""
                grdCommodities.Columns("Document2").Text = rsCommodity("Document2") & ""
                If Not IsNumeric(grdCommodities.Columns("Unit Value")) _
                    Then grdCommodities.Columns("Unit Value") = "0"
                If IsNumeric(rsCommodity("g_str1030") & "") Then
                    If CDbl(rsCommodity("g_str1030") & "") > 0 Then
                        grdCommodities.Columns("Unit Value") _
                            = rsCommodity("g_str1030") & ""
                    End If
                End If
                If IsNumeric(grdCommodities.Columns("Quantity")) _
                    Then grdCommodities.Columns("Customs Val") _
                        = Format(CDbl(grdCommodities.Columns("Quantity") & "") * CDbl(grdCommodities.Columns("Unit Value") & ""), "0.00")
                        
                        'Quantity
'            Else
'                Debug.Assert False
'
'                grdCommodities.Columns("MID").Text = ""
'                grdCommodities.Columns("Document1").Text = ""
'                grdCommodities.Columns("Document2").Text = ""
            End If
            
        End If
        
        ' Change to Part Number
        If grdCommodities.Columns("Part Number").Text <> "" _
        And (grdCommodities.Columns(grdCommodities.col).Caption = "Part Number") Then
            
            i = InStr(1, grdCommodities.Columns("Description").Text, "; Part")
            If i <> 0 Then
                j = InStr(i + 11, grdCommodities.Columns("Description").Text, ";")
                If j > 0 Then
                    grdCommodities.Columns("Description").Text _
                        = Left(grdCommodities.Columns("Description").Text, i - 1) _
                        & Mid(frmShip.f79.Text, j, 255)
                Else
                    grdCommodities.Columns("Description").Text _
                        = Left(grdCommodities.Columns("Description").Text, i - 1)
                End If
            End If
            grdCommodities.Columns("Description").Text _
                = grdCommodities.Columns("Description").Text _
                & "; Part " & grdCommodities.Columns("CommodityID").Text _
                & " " & grdCommodities.Columns("Part Number").Text
        End If
            
            
            
        
    End If
    If c1.name = "optCommodities" Then
        If frmShip.optCommodities.Value Then
            g_clsReg.SetRegistryValue "Carry_Commodities", "C", REG_SZ
        End If
    End If
    If c1.name = "optDocument" Then
        If frmShip.optDocument.Value Then
            g_clsReg.SetRegistryValue "Carry_Commodities", "D", REG_SZ
            If frmShip.chkIntlIPD.Value = 1 Then
                frmShip.chkIntlIPD.Value = 0
                Call frmShip.EnableDisableIPD(False)
            End If
            If Right(frmShip.cboLocationName(0).Text, 3) = "IPD" Then
                frmShip.SetLocationName Left(frmShip.cboLocationName(0).Text, (Len(frmShip.cboLocationName(0).Text) - 3))
                Call AfterLostFocus(frmShip.cboLocationName(0))
                Call frmShip.EnableDisableIPD(frmShip.chkIntlIPD) ' Again on location change
            End If
            If Left(frmShip.f1274.Text, 2) = "18" Then
                frmShip.f1274.Text = "01"
            End If
        End If
    End If
    If c1.name = "chkIntlIPD" Then
        If frmShip.chkIntlIPD.Value = 1 And Left(frmShip.f50.Text, 2) <> "US" Then
            frmShip.chkIntlIPD.Value = 0
            Call frmShip.EnableDisableIPD(False)
            Call frmShip.EnableDisableIPD(frmShip.chkIntlIPD) ' Again on location change
        End If
        If frmShip.chkIntlIPD.Value = 1 Then
            If Right(frmShip.cboLocationName(0).Text, 3) <> "IPD" Then
                frmShip.SetLocationName frmShip.cboLocationName(0).Text & "IPD"
                Call AfterLostFocus(frmShip.cboLocationName(0))
                Call frmShip.EnableDisableIPD(frmShip.chkIntlIPD) ' Again on location change
            End If
            If Left(frmShip.f1274.Text, 2) <> "18" Then
                frmShip.f1274.Text = "18"
            End If
            If frmShip.optDocument.Value Then frmShip.optDocument.Value = 0
            If Not frmShip.optCommodities.Value Then frmShip.optCommodities.Value = 1
        Else
            If Right(frmShip.cboLocationName(0).Text, 3) = "IPD" Then
                frmShip.SetLocationName Left(frmShip.cboLocationName(0).Text, (Len(frmShip.cboLocationName(0).Text) - 3))
                Call frmShip.EnableDisableIPD(frmShip.chkIntlIPD) ' Again on location change
            End If
            If Left(frmShip.f1274.Text, 2) = "18" Then
                frmShip.f1274.Text = g_clsReg.GetRegistryValue("Carry_f1274", "92")
            End If
        End If
        g_clsReg.SetRegistryValue "Carry_IPD", frmShip.chkIntlIPD.Value, REG_SZ
        If frmShip.f1274.ListIndex = -1 Then frmShip.f1274.ListIndex = 0
    End If
    If c1.name = "cboLocationName" Then
        If c1.Text <> "" Then
            If c1.ListIndex >= 0 Then
                g_clsReg.SetRegistryValue "Carry_LocationName", c1.Text, REG_SZ
            End If
            If UCase(Right(c1.Text, 3)) = "IPD" And Left(frmShip.f50.Text, 2) = "US" Then
                If frmShip.chkIntlIPD.Value = 0 Then
                    frmShip.chkIntlIPD.Value = 1
                    Call frmShip.EnableDisableIPD(frmShip.chkIntlIPD.Value)
                    frmShip.f1274.Text = "18"
                End If
                If frmShip.optDocument.Value Then frmShip.optDocument.Value = 0
                If Not frmShip.optCommodities.Value Then frmShip.optCommodities.Value = 1
            Else
                If frmShip.chkIntlIPD.Value = 1 Then
                    frmShip.chkIntlIPD.Value = 0
                    Call frmShip.EnableDisableIPD(False)
                    If Left(frmShip.f1274.Text, 2) = "18" Then
                        frmShip.f1274.Text = g_clsReg.GetRegistryValue("Carry_f1274", "92")
                    End If
                End If
            End If
            If c1.Text <> "" Then
                If UCase(Right(c1.Text, 3)) = "IPD" Or UCase(c1.Text) = "USRETURN" Then
                    If Not frmSetup.f1586.Value Or frmSetup.cboAddrID.Text <> "USRETURN" Then
                        Call frmSetup.LoadAltReturnAddrForm("AddrID", "USRETURN")
                        Call frmSetup.AssignSetupToGlobalVars
                    End If
                Else
                    If Left(frmShip.f50, 2) = "CA" Then
                        If Not frmSetup.f1586.Value Or frmSetup.cboAddrID.Text <> "CARETURN" Then
                            Call frmSetup.LoadAltReturnAddrForm("AddrID", "CARETURN")
                            Call frmSetup.AssignSetupToGlobalVars
                        End If
                    Else
                        If frmSetup.f1586.Value Then
                            Call frmSetup.LoadAltReturnAddrForm("AddrID", "")
                            Call frmSetup.AssignSetupToGlobalVars
                        End If
                    End If
                End If
            End If
        End If
        If frmShip.f1274.ListIndex = -1 And frmShip.f1274.ListCount > 0 Then frmShip.f1274.ListIndex = 0
    End If
    
    If (c1.name = "f50" Or c1.name = "f116" Or c1.name = "f1670" _
    Or c1.name = "f1274" Or c1.name = "f1273" Or c1.name = "f17") Then
        If frmShip.f50.Text <> "" _
        And frmShip.f1274.Text <> "" _
        And frmShip.f17.Text <> "" _
        And frmShip.f116.Text <> "" And IsNumeric(frmShip.f116.Text) _
        And frmShip.f1670.Text <> "" And IsNumeric(frmShip.f1670.Text) Then
            Call frmShip.RateShipScreen
        End If
    End If
    
    i = 0
    
    ' For i = 0 To frmShip.f2382.UBound
        If frmShip.f2382(i).Value = 1 Then
            If Left(frmShip.f1274.Text, 2) = "18" Or UCase(frmShip.cboLocationName(0).Text) = "USRETURN" Then
                If frmReturnLbl.cboAddrID.Text <> "USRETURN" Then
                    frmReturnLbl.cboAddrID.Text = "USRETURN"
                    Call LoadReturnAddrForm("AddrID", frmReturnLbl.cboAddrID, frmReturnLbl)
                    Call frmReturnLbl.AssignFormGlobalVars
                End If
            Else
                If frmReturnLbl.cboAddrID.Text <> "CARETURN" Then
                    frmReturnLbl.cboAddrID.Text = "CARETURN"
                    Call LoadReturnAddrForm("AddrID", frmReturnLbl.cboAddrID, frmReturnLbl)
                    Call frmReturnLbl.AssignFormGlobalVars
                End If
            End If
            If Left(frmReturnLbl.f1274.Text, 2) <> "92" Then
                frmReturnLbl.f1274.Text = "92"
                Call frmReturnLbl.AssignFormGlobalVars
            End If
        End If
    ' Next
    
    If c1.name = "cboCommodityID" Then
        If frmShip.cboCommodityID.Text <> "" Then
            If frmShip.f1275.Text = "" Then
                frmShip.f1275.Text = frmShip.cboCommodityID.Text
            ElseIf frmShip.f1275.Text = frmShip.cboCommodityID.Text Then
            ElseIf frmShip.f120.Text = "" Then
                frmShip.f120.Text = frmShip.cboCommodityID.Text
            End If
        End If
    End If
    
    Exit Sub
    
EH:
    MsgBox Err.Description, , "modODBC.AfterLostFocus"
    Debug.Assert False
    If False Then
        Resume
    End If
    
End Sub
'

'---------------------------------------------------------------------------------------
' Procedure : AfterClose()
' DateTime  : 7/5/2004
' Purpose   : REQUIRED SUB. Can be used as hook to call routines to be executed after
'             FXRS Close.
'---------------------------------------------------------------------------------------
'
Public Sub AfterClose()

End Sub
'

' 2007-04-13, JFW, Allow for custom screen display.
Public Sub AfterConnect()

    ' 2007-12-07, JFW, Large address book making a slow start on some clients.
    ' Call frmShip.ToggleLookup(True)
    On Error Resume Next
    'Call frmShip.ToggleDepartment(True)
    frmShip.f70.ListIndex = 0
    frmShip.f72.ListIndex = 0
    frmShip.f38 = g_clsReg.GetRegistryValue("Carry_f38", "")
    frmShip.f50 = g_clsReg.GetRegistryValue("Carry_f50", "")
    frmShip.f75 = g_clsReg.GetRegistryValue("Carry_f75", "")
    frmShip.f1274 = g_clsReg.GetRegistryValue("Carry_f1274", "")
    If frmShip.f1274.ListIndex = -1 And frmShip.f1274.ListCount > 0 Then frmShip.f1274.ListIndex = 0
    frmShip.f1273 = g_clsReg.GetRegistryValue("Carry_f1273", "")
    If g_clsReg.GetRegistryValue("Carry_Commodities", "") = "C" Then frmShip.optCommodities.Value = True
    If g_clsReg.GetRegistryValue("Carry_Commodities", "") = "D" Then frmShip.optDocument.Value = True
    Call frmShip.SetLocationName(g_clsReg.GetRegistryValue("Carry_LocationName", ""))
    
End Sub
'

' 2007-04-13, JFW, Allow for custom screen display.
Public Sub AfterDisconnect()

    On Error Resume Next
    
End Sub
'

'---------------------------------------------------------------------------------------
' Procedure : AfterRateQuote()
' DateTime  : 20071106-01
' Purpose   : REQUIRED SUB. Can be used as hook to call routines to be executed after
'             a rate quote.
'---------------------------------------------------------------------------------------
'
Public Sub AfterRateQuote()

    If Left(frmShip.f1274.Text, 2) = "18" Then
        m_str37 = g_str37
    Else
        m_str37 = ""
    End If
    
End Sub
'

' 2012-01-19, JFW, New for UCS.
Public Function AfterScreenChange(f As Form) As Boolean

End Function
'

'---------------------------------------------------------------------------------------
' Procedure : BeforeBatch()
' DateTime  : 20070621-01 Changed BeforeBatch to return a boolean
' Purpose   : REQUIRED SUB. Called before an entire batch is processed.
'---------------------------------------------------------------------------------------
'
Public Function BeforeBatch() As Boolean

    BeforeBatch = True

End Function
'

'---------------------------------------------------------------------------------------
' Procedure : BeforeBatchShip()
' DateTime  : 20070822-02 Modified BeforeBatchShip to return a Boolean.
' Purpose   : REQUIRED SUB. Called just before a batch transaction is sent to the server.
'---------------------------------------------------------------------------------------
'
Public Function BeforeBatchShip() As Boolean

    BeforeBatchShip = True

End Function
'

'---------------------------------------------------------------------------------------
' Procedure : BeforeClose()
' DateTime  : 7/12/2006
' Purpose   : REQUIRED SUB. Can be used as hook to call routines to be executed before
'             FXRS Close.
'---------------------------------------------------------------------------------------
'
Public Function BeforeClose() As Boolean

    BeforeClose = True

End Function
'


' 2012-01-19, JFW, New for UCS.
Public Function BeforeGotFocus(f As Form, c As Control) As Boolean
    On Error GoTo Test
    Exit Function
Test:
    DebugPrint "BeforeGotFocus, " & Err.Description
    
End Function

'---------------------------------------------------------------------------------------
' Procedure : BeforeShip()
' DateTime  : 2/21/2005
' Purpose   : REQUIRED Function. Modified to Return Boolean which controls whether or not
'             the shipment will continue or be canceled. Return True to continue shipment,
'             False to cancel.
'---------------------------------------------------------------------------------------
'
Public Function BeforeShip(Optional ByRef TransString As String = "") As Boolean

    On Error GoTo EH
    
    Dim f As Form
    Dim frmComm As frmCommodities
    Dim strQuery As String
    Dim rsCommodity As New ADODB.Recordset
    Dim strOrderNum As String
    Dim lngCount As Long
    
    BeforeShip = True
    If Left(frmShip.f1274.Text, 2) = "18" Then
        If m_str37 = "" Then
            frmMsgBox.ShowMessage "IPD rating in progress.  Try again in a moment.", 2000
            BeforeShip = False
        End If
    End If

    With frmShip
        If .f1.Visible Then
            strOrderNum = .f1.Text
        Else
            strOrderNum = .cboCustID.Text
        End If
    End With

    Call SaveCommodities
    
    strQuery = "SELECT * FROM IntlCommodities WHERE f1 = '" & strOrderNum & "'"
    strQuery = strQuery & " AND Workstation = '" & g_strComputerName & "'"
    strQuery = strQuery & " AND (g_str29 IS NULL OR g_str29 = '')"
    rsCommodity.Open strQuery, g_connFSMSClient, adOpenStatic, adLockOptimistic
    
    Do While Not rsCommodity.EOF
        If Trim(rsCommodity!g_str1275 & "") <> "" _
        And Trim(rsCommodity!g_str80 & "") <> "" _
        And Trim(rsCommodity!CommodityID & "") <> "" Then
            strQuery = "UPDATE CDIPartCommodity SET"
            strQuery = strQuery & " CommodityID = '%CommodityID'"
            strQuery = strQuery & " WHERE PartNumber = '%PartNumber'"
            strQuery = Replace(strQuery, "%CommodityID", Trim(rsCommodity!CommodityID & ""))
            strQuery = Replace(strQuery, "%PartNumber", Trim(rsCommodity!g_str1275 & ""))
            Call g_connFSMSClient.Execute(strQuery, lngCount)
            If lngCount <= 0 Then
                strQuery = "INSERT INTO CDIPartCommodity"
                strQuery = strQuery & " ( PartNumber, CommodityID )"
                strQuery = strQuery & " Values"
                strQuery = strQuery & " ('%PartNumber', '%CommodityID' )"
                strQuery = Replace(strQuery, "%CommodityID", Trim(rsCommodity!CommodityID & ""))
                strQuery = Replace(strQuery, "%PartNumber", Trim(rsCommodity!g_str1275 & ""))
                Call g_connFSMSClient.Execute(strQuery, lngCount)
            End If
        End If
        rsCommodity.MoveNext
    Loop

'
'    If g_clsReg.GetRegistryValue("Carry_LocationName", "") <> "" Then
'        If frmShip.cboLocationName(0).Text <> g_clsReg.GetRegistryValue("Carry_LocationName", "") Then
'            Call frmShip.SetLocationName(g_clsReg.GetRegistryValue("Carry_LocationName", ""))
'            Call AfterLostFocus(frmShip.cboLocationName(0))
'

    Exit Function
EH:
    MsgBox Err.Description, vbCritical, "ODBCCDI:BeforeShip"

End Function
'

'---------------------------------------------------------------------------------------
' Procedure : BeforeShipTrans()
' DateTime  : 8/7/2008
' Purpose   : REQUIRED Function. Modified to Return Boolean which controls whether or not
'             the shipment will continue or be canceled. Return True to continue shipment,
'             False to cancel.
'---------------------------------------------------------------------------------------
'
Public Function BeforeShipTrans(ByRef TransString As String) As Boolean
    
    Dim i As Long
    Dim lngMsgBoxResult As VbMsgBoxResult
    
    If 0 <> InStr(1, TransString, ",1,""RATE ONLY""") Then
        m_str37 = ""
    End If
    
    TransString = Replace(TransString, "99,""""", "")
    
    If 0 = InStr(1, TransString, """1,""IPD MAWB") Then
    If 0 = InStr(1, TransString, """1,""RATE ONLY") Then
        ' 2014-10-16, JFW, Country on label, not returns
        If 0 = InStr(1, TransString, """1,""RETURN") Then
            If g_str187 = "388" Or g_str187 = "488" Then
                ' Service type                             Text              X                     Y                           Country                 ?                         Font
                TransString = TransString & "2429-1" & ",""03""2430-1" & ",""600""2431-1" & ",""" & CStr(25) & """2432-1" & ",""" & g_str50 & """" & "2433-1" & ",""""" & "2434-1" & ",""" & CStr(16) & """"
            End If
        End If
        
        If 0 <> InStr(1, TransString, """1,""RETURN") Then
            ' US return account with IPD on screen
            ' CA account otherwise.
            If 0 <> InStr(1, TransString, """117,""US""") Then
            If 0 <> InStr(1, TransString, """50,""US""") Then
                g_str10 = "581015488"
                ' Too broad to SetLocationName
                ' frmShip.SetLocationName "USRETURN"
                frmShip.cboLocationName(0).Text = "USRETURN"

                TransString = Replace(TransString, """10,""125291724""", """10,""581015488""")
            End If
            End If
            
        ElseIf g_str1274 = "18" Then
            If g_str187 = "388" Or g_str187 = "488" Then
                ' Service type                             Text              X                     Y                           IPD                    ?                         Font
                TransString = TransString & "2429-2" & ",""03""2430-2" & ",""40""2431-2" & ",""" & CStr(25) & """2432-2" & ",""IPD""" & "2433-2" & ",""""" & "2434-2" & ",""" & CStr(16) & """"
            End If
        
        ElseIf g_str1274 = "92" Then
            If g_str187 = "388" Or g_str187 = "488" Then
                ' Service type                             Text              X                     Y                           GND                    ?                         Font
                TransString = TransString & "2429-2" & ",""03""2430-2" & ",""40""2431-2" & ",""" & CStr(25) & """2432-2" & ",""GND""" & "2433-2" & ",""""" & "2434-2" & ",""" & CStr(16) & """"
            End If
        End If
    
        If g_str187 = "388" Or g_str187 = "488" Then
            ' Reference                              Text              X                     Y                            Ref                                    ?                         Font
            TransString = TransString & "2429-3" & ",""03""2430-3" & ",""40""2431-3" & ",""" & CStr(225) & """2432-3" & ",""Ref: " & g_str25 & """" & "2433-3" & ",""""" & "2434-3" & ",""" & CStr(8) & """"
        End If
        
    End If
    End If
    
'               Test different fonts
'                For i = 1 To 10
'                    TransString = TransString & "2429-" & CStr(i) & ",""03""2430-" & CStr(i) & ",""40""2431-" & CStr(i) & ",""" & CStr(i * 25) & """2432-" & CStr(i) & ",""IPD " & CStr(i) & """2433-" & CStr(i) & ",""""2434-" & CStr(i) & ",""" & CStr(i + 20) & """"
'                Next i
    
    TransString = TransString & "99,"""""
    
    BeforeShipTrans = True
    
End Function
'

'---------------------------------------------------------------------------------------
' Procedure : BuildCustomSPLabel()
' DateTime  : 20070620-04
' Purpose   : REQUIRED SUB. Can be used as hook to create custom EPL or ZPL buffer labels
'             for SmartPost.
'---------------------------------------------------------------------------------------
'
Public Function BuildCustomSPLabel(ByVal strLabel As String) As String

    BuildCustomSPLabel = strLabel

End Function
'

Public Function ClearCommodity() As Boolean

End Function
'

Public Function ClearShipScreen() As Boolean

    On Error Resume Next
    
    m_str37 = ""
    
    If Not m_rsOrder Is Nothing Then
    If m_rsOrder.State <> adStateClosed Then
        m_rsOrder.Close
        DoEvents
    End If
    End If
    
    If frmShip.f38 <> g_clsReg.GetRegistryValue("Carry_f38", "") Then
        frmShip.f38 = g_clsReg.GetRegistryValue("Carry_f38", "")
    End If
    If Left(frmShip.f50, 2) <> g_clsReg.GetRegistryValue("Carry_f50", "") Then
        frmShip.f50 = g_clsReg.GetRegistryValue("Carry_f50", "")
        Call AfterLostFocus(frmShip.f50)
    End If
    frmShip.f75 = g_clsReg.GetRegistryValue("Carry_f75", "")
    
    If g_clsReg.GetRegistryValue("Carry_Commodities", "") = "C" Then frmShip.optCommodities.Value = True
    If g_clsReg.GetRegistryValue("Carry_Commodities", "") = "D" Then frmShip.optDocument.Value = True
    If g_clsReg.GetRegistryValue("Carry_LocationName", "") <> "" Then
        If frmShip.cboLocationName(0).Text <> g_clsReg.GetRegistryValue("Carry_LocationName", "") Then
            Call frmShip.SetLocationName(g_clsReg.GetRegistryValue("Carry_LocationName", ""))
            Call AfterLostFocus(frmShip.cboLocationName(0))
        End If
    End If
    If Trim(Left(frmShip.f1274, 3)) <> g_clsReg.GetRegistryValue("Carry_f1274", "") Then
        If Not frmShip.chkIntlIPD.Value Then
            frmShip.f1274 = g_clsReg.GetRegistryValue("Carry_f1274", "")
            Call AfterLostFocus(frmShip.f1274)
        End If
    End If
    If frmShip.f1274.ListIndex = -1 And frmShip.f1274.ListCount > 0 Then frmShip.f1274.ListIndex = 0
    frmShip.f1273 = g_clsReg.GetRegistryValue("Carry_f1273", "")

End Function
'

'---------------------------------------------------------------------------------------
' Procedure : Connect()
' DateTime  : 7/5/2004
' Purpose   : Open connection to ODBC test DSN. Instantiate module level recordset.
'---------------------------------------------------------------------------------------
'
Private Function Connect() As Boolean
    On Local Error GoTo Handler
    Dim strDSN As String
    Dim boolSecondTry As Boolean

    If m_CNIn Is Nothing Then
        Set m_CNIn = New ADODB.Connection
    End If
    If m_CNOut Is Nothing Then
        Set m_CNOut = New ADODB.Connection
    End If

    If m_CNIn.State <> adStateOpen Then   'if connection is not open then do so
        If GetSystemName = "WINXPC9CA96EA3" Then
            m_CNIn.Open "Driver={SQL Server};Server=CAN-00406583;Database=FedExCDI;Uid=sa;Pwd=john2014;"
            frmShip.StatusBar1.Panels(2).Text = "CDI data in " & "FedExCDI"
            Pause 1
        'ElseIf GetSystemName = "WINXPC9CA96EA3" Then
        '    m_CNIn.Open "Driver={SQL Server};Server=CAN-00406583;Database=FSMSClientV800CA;Uid=sa;Pwd=john2014;"
        Else
            If g_clsSettings.Setting("IntegrationFileIn") = "" Then
                ' g_clsSettings.Setting("IntegrationFileIn") = "Driver={SQL Server};Server=ONDB08;Database=;Uid=Fedex;Pwd=f3d3xdb;"
                g_clsSettings.Setting("IntegrationFileIn") = "Driver={SQL Server};Server=ON-FEDEX-S1;Database=;Uid=sa;Pwd=FEDEXUSER;"
                g_clsSettings.SaveSettings
            End If
            m_CNIn.Open g_clsSettings.Setting("IntegrationFileIn")
            If g_clsSettings.Setting("CDIDatabase") = "" Then
                g_clsSettings.Setting("CDIDatabase") = "Fedex_Development"
                g_clsSettings.SaveSettings
            End If
            frmShip.StatusBar1.Panels(2).Text = "CDI data in " & g_clsSettings.Setting("CDIDatabase")
            Pause 1
        End If
    End If

    If m_CNOut.State <> adStateOpen Then   'if connection is not open then do so
        If GetSystemName = "WINXPC9CA96EA3" Then
            m_CNOut.Open "Driver={SQL Server};Server=CAN-00406583;Database=FedExCDI;Uid=sa;Pwd=john2014;"
        Else
            If g_clsSettings.Setting("IntegrationFileOut") = "" Then
                ' g_clsSettings.Setting("IntegrationFileOut") = "Driver={SQL Server};Server=ONDB08;Database=;Uid=Fedex;Pwd=f3d3xdb;"
                g_clsSettings.Setting("IntegrationFileOut") = "Driver={SQL Server};Server=ONDB08;Database=;Uid=fedex;Pwd=f3d3xdb;"
                g_clsSettings.SaveSettings
            End If
            m_CNOut.Open g_clsSettings.Setting("IntegrationFileOut")
        End If
    End If

    Connect = True

    Exit Function

Handler:
'    If Not boolSecondTry Then
'        boolSecondTry = True
'        If Err.number = -2147467259 Then
'            Call AddDSN
'            Resume
'        End If
'    End If
    MsgBox Err.Description, , "modODBC.Connect"
    ' Call Kill        'kill connection and recordset

End Function
'

'---------------------------------------------------------------------------------------
' Procedure : GetData()
' DateTime  : 7/5/2004
' Purpose   : REQUIRED SUB. Called from frmShip.f1_LostFocus, which is the OrderID field.
'             Call routines needed to get data from the customer's system and assign the
'             value to the appropriate fields on the Ship form. This example uses ODBC.
'---------------------------------------------------------------------------------------
'
Public Function GetData(ByVal strKey As String) As Boolean
    On Local Error GoTo Handler
    Dim i As Long
    Dim strSQL As String
    Dim strSQL2 As String
    Dim strData As String
    Dim strStep As String
    
Retry:
    If m_CNIn Is Nothing Then
        Call Connect
    End If

    strSQL = ""
    If GetSystemName = "WINXPC9CA96EA3" And strStep = "" Then
        strStep = "Dash"
        If Not IsNumeric(strKey) Then GoTo Retry
        strSQL = strSQL & "SELECT cst.*, oh.* "
        strSQL = strSQL & "FROM [OrderHdr] oh "
        strSQL = strSQL & "JOIN [CustShipTo] cst "
        strSQL = strSQL & "ON oh.[OHSHIPTO_CODE]=cst.[SH_UNIQUE] "
        strSQL = strSQL & "WHERE ohno=%orderno "
    
        strSQL2 = "SELECT * from FedExOrderHdr (%orderno)"
    
    ElseIf GetSystemName = "WINXPC9CA96EA3" And strStep = "Dash" Then
        strStep = "EOL"
        If Not IsNumeric(strKey) Then GoTo Retry
        strSQL = strSQL & "SELECT * FROM EolHdr "
        strSQL = strSQL & "WHERE LTRIM(RTRIM(cPoNumb)) = '%orderno' "
    ElseIf GetSystemName = "WINXPC9CA96EA3" And strStep = "EOL" Then
        strStep = "Addr"
        strSQL = strSQL & "select * from Customer "
        strSQL = strSQL & "Where "
        strSQL = strSQL & "CCODE = '%orderno' "
    ElseIf GetSystemName = "WINXPC9CA96EA3" Then
        strStep = ""
        GetData = False
        Exit Function
    ElseIf 0 <> InStr(1, LCase(frmShip.cboLocationName(0).Text), "jdh") Then
        If Not IsNumeric(strKey) Then
            Err.Raise 12345, "GetData", "Numeric order number required."
        End If
        strSQL = strSQL & "SELECT cst.*, oh.* "
        strSQL = strSQL & "FROM %database.[dbo].[OrderHdr] oh "
        strSQL = strSQL & "JOIN %database.[dbo].[CustShipTo] cst "
        strSQL = strSQL & "ON oh.[OHSHIPTO_CODE]=cst.[SH_UNIQUE] "
        strSQL = strSQL & "WHERE ohno=%orderno "
        
        strSQL = "SELECT * from %database.dbo.FedExOrderHdr (%orderno)"
        
    ElseIf 0 <> InStr(1, LCase(frmShip.cboLocationName(0).Text), "eol") Then
        If Not IsNumeric(strKey) Then
            Err.Raise 12345, "GetData", "Numeric PO number required."
        End If
        strSQL = strSQL & "SELECT * FROM %database.[dbo].[EolHdr] "
        strSQL = strSQL & "WHERE LTRIM(RTRIM([cPoNumb])) = '%orderno' "
    ElseIf True Then
        strSQL = strSQL & "select * from %database.[dbo].[Customer] "
        strSQL = strSQL & "Where "
        strSQL = strSQL & "[CCODE] = '%orderno' "
    End If
    strSQL = Replace(strSQL, "%orderno", strKey)
    strSQL = Replace(strSQL, "%database", g_clsSettings.Setting("CDIDatabase"))
    
    If m_rsOrder Is Nothing Then Set m_rsOrder = New ADODB.Recordset
    If Not m_rsOrder Is Nothing Then
    If m_rsOrder.State <> adStateClosed Then
        m_rsOrder.Close
        DoEvents
    End If
    End If
    DebugPrint strSQL
    m_rsOrder.CursorLocation = adUseClient
    m_rsOrder.Open strSQL, m_CNIn, adOpenStatic

    If m_rsOrder.BOF And m_rsOrder.EOF Then
        'No records found for that order number
        m_rsOrder.Close
        If strStep <> "" Then GoTo Retry
        GetData = False
        Exit Function
    End If
    
    If m_rsExt Is Nothing Then Set m_rsExt = New ADODB.Recordset
    If Not m_rsExt Is Nothing Then
    If m_rsExt.State <> adStateClosed Then
        m_rsExt.Close
        DoEvents
    End If
    End If
    strSQL2 = ""
    If GetSystemName = "WINXPC9CA96EA3" And strStep = "Dash" Then
        strSQL2 = "SELECT rmaticket, ordertypeid FROM [ORDERHDR_EXT] WHERE orderno = %orderno"
    ElseIf GetSystemName = "WINXPC9CA96EA3" And strStep = "Dash" Then
        strSQL2 = ""
    ElseIf GetSystemName = "WINXPC9CA96EA3" Then
        strStep = ""
    ElseIf 0 <> InStr(1, LCase(frmShip.cboLocationName(0).Text), "jdh") Then
        strSQL2 = "SELECT rmaticket, ordertypeid FROM %database.[dbo].[ORDERHDR_EXT] WHERE orderno = %orderno"
        strSQL2 = "SELECT * from %database.dbo.FedExOrderExt (%orderno)"
    ElseIf 0 <> InStr(1, LCase(frmShip.cboLocationName(0).Text), "eol") Then
        '
    ElseIf True Then
        '
    End If
    strSQL2 = Replace(strSQL2, "%orderno", strKey)
    strSQL2 = Replace(strSQL2, "%database", g_clsSettings.Setting("CDIDatabase"))
    If strSQL2 <> "" Then
        DebugPrint strSQL2
        m_rsExt.CursorLocation = adUseClient
        m_rsExt.Open strSQL2, m_CNIn, adOpenStatic
    End If
    
    If m_rsProduct Is Nothing Then Set m_rsProduct = New ADODB.Recordset
    If Not m_rsProduct Is Nothing Then
    If m_rsProduct.State <> adStateClosed Then
        m_rsProduct.Close
        DoEvents
    End If
    End If
    strSQL2 = ""
    If GetSystemName = "WINXPC9CA96EA3" And strStep = "Dash" Then
        strSQL2 = "SELECT pr.*, od.* FROM OrderDet od LEFT JOIN Products pr ON IBPARTN = OLPARTN WHERE OL_ORDERNO = %orderno ORDER BY OL_LINE_NO"
        strSQL2 = "SELECT * from FedExOrderDet (%orderno) ORDER BY OL_LINE_NO"
    ElseIf GetSystemName = "WINXPC9CA96EA3" And strStep = "Dash" Then
        strSQL2 = ""
    ElseIf GetSystemName = "WINXPC9CA96EA3" Then
        strStep = ""
    ElseIf 0 <> InStr(1, LCase(frmShip.cboLocationName(0).Text), "jdh") Then
        
        strSQL2 = "SELECT pr.*, od.* FROM %database.[dbo].OrderDet od LEFT JOIN %database.[dbo].Products pr ON IBPARTN = OLPARTN WHERE OL_ORDERNO = %orderno "
        
'        strSQL2 = "SELECT OLPARTN, OLCOST, OLSELL, OL_WHSE, OL_ORDERNO, OLSHIPPED, OL_LINE_NO, OL_UOM, OL_MODEL_NO, OL_PROD_TYPE"
'        strSQL2 = strSQL2 & " FROM %database.[dbo].OrderDet WHERE OL_ORDERNO = %orderno"
'
'        strSQL2 = "SELECT OLPARTN, OL_ORDERNO"
'        strSQL2 = strSQL2 & " FROM %database.[dbo].OrderDet WHERE OL_ORDERNO = %orderno"
    
        strSQL2 = "SELECT * from %database.dbo.FedExOrderDet (%orderno) "
    
    ElseIf 0 <> InStr(1, LCase(frmShip.cboLocationName(0).Text), "eol") Then
        '
    ElseIf True Then
        '
    End If
    strSQL2 = Replace(strSQL2, "%orderno", strKey)
    strSQL2 = Replace(strSQL2, "%database", g_clsSettings.Setting("CDIDatabase"))
    If strSQL2 <> "" Then
        DebugPrint strSQL2
        m_rsProduct.CursorLocation = adUseClient
        m_rsProduct.Open strSQL2, m_CNIn, adOpenStatic
    End If
    
'    strData = ""
'    If m_rsOrder.EOF Then
'        strData = "No records"
'    Else
'        For i = 0 To m_rsOrder.Fields.Count - 1
'            strData = strData & vbCrLf & m_rsOrder.Fields(i).name & " " & m_rsOrder.Fields(i).Value
'        Next i
'    End If
'
'    strData = "Record count " & m_rsOrder.RecordCount & vbCrLf & strData
    
    DebugPrint "ToShip count " & m_rsOrder.RecordCount & ", " & m_rsProduct.RecordCount
    
    Call GetDataToShip(strKey)

    DebugPrint "GetData done"
    
    GetData = True
Release:
    ' call kill
    Exit Function
Handler:
    MsgBox Err.Description, , "modODBC.GetData"
    ' Call Kill
    Resume Release
    Resume
    
End Function
'

'---------------------------------------------------------------------------------------
' Procedure : GetDataToShip()
' DateTime  : 7/5/2004
' Purpose   : REQUIRED SUB. Called from frmShip.f1_LostFocus, which is the OrderID field.
'             Call routines needed to get data from the customer's system and assign the
'             value to the appropriate fields on the Ship form. This example uses ODBC.
'---------------------------------------------------------------------------------------
'
Public Sub GetDataToShip(strKey As String)

    On Local Error GoTo Handler

    Dim strPhone As String
    Dim strCity As String
    Dim strZip As String
    Dim strState As String
    Dim i As Long
        
    With frmShip
        
        If UCase(m_rsOrder.Fields(0).name) = UCase("CustID") Then

            Call GetDataToShipAddressBook(strKey)
            
        ElseIf m_rsOrder.Fields(0).name = "SHSEQ" _
        Or m_rsOrder.Fields(0).name = "OHNO" Then

            Call GetDataToShipDashboard(strKey)
            
        ElseIf m_rsOrder.Fields(0).name = "nEOL_id" Then

            Call GetDataToShipEOL(strKey)
            
        ElseIf m_rsOrder.Fields(0).name = "CCODE" Then

            Call GetDataToShipCustomer(strKey)
            
        Else
            Err.Raise 12345, "GetDataToShip", "Invalid recordset."
            
        End If
                
        If Left(.f50.Text, 2) = "US" Then
            If 0 <> InStr(1, LCase(.cboLocationName(0).Text), "jdh") _
            Or 0 <> InStr(1, LCase(.cboLocationName(0).Text), "eol") Then
                If Not .chkIntlIPD.Value Then
                    .chkIntlIPD.Value = 1
                    Call frmShip.EnableDisableIPD(.chkIntlIPD)
                End If
                If Left(frmShip.f1274.Text, 2) <> "18" Then
                    frmShip.f1274.Text = "18"
                End If
                If frmShip.optDocument.Value Then frmShip.optDocument.Value = 0
                If Not frmShip.optCommodities.Value Then frmShip.optCommodities.Value = 1
            Else
                ' Marketing carries whatever service in use
            End If
        Else
            If Right(UCase(.cboLocationName(0).Text), 3) = "IPD" Then
                frmShip.SetLocationName Left(frmShip.cboLocationName(0).Text, (Len(frmShip.cboLocationName(0).Text) - 3))
            End If
            If .chkIntlIPD.Value Then
                .chkIntlIPD.Value = 0
                Call frmShip.EnableDisableIPD(.chkIntlIPD)
            End If
            If 0 <> InStr(1, LCase(.cboLocationName(0).Text), "jdh") _
            Or 0 <> InStr(1, LCase(.cboLocationName(0).Text), "eol") Then
                If Left(frmShip.f1274.Text, 2) <> g_clsReg.GetRegistryValue("Carry_f1274", "92") Then
                    frmShip.f1274.Text = g_clsReg.GetRegistryValue("Carry_f1274", "92")
                End If
            Else
                ' Marketing carries service
            End If
        End If
        
        If .f2382(0).Value = 1 Then
            frmReturnLbl.chkNoShipLabel.Value = 0
        End If
        
        If frmShip.f116.Enabled Then
            frmShip.f116.SetFocus
        Else
            frmShip.f1670.SetFocus
        End If
        
        
    End With
    
    g_strErrorLocation = "Done"

Release:
    Exit Sub
Handler:
    If Err.number = 13 Then
        Resume Next
    Else
        MsgBox Err.Description & " (GetDataToShip)", vbSystemModal
    End If
    
    MsgBox "Error at " & g_strErrorLocation & " - " & Err.Description, , _
        "modODBC.GetDataToShip"
    Resume Release
    Resume

End Sub
'

'---------------------------------------------------------------------------------------
' Procedure : GetDataToShipAddressBook()
' DateTime  : 7/5/2004
' Purpose   : REQUIRED SUB. Called from frmShip.f1_LostFocus, which is the OrderID field.
'             Call routines needed to get data from the customer's system and assign the
'             value to the appropriate fields on the Ship form. This example uses ODBC.
'---------------------------------------------------------------------------------------
'
Public Sub GetDataToShipAddressBook(strKey As String)

    On Local Error GoTo Handler

    Dim strPhone As String
    Dim strCity As String
    Dim strZip As String
    Dim strState As String
    Dim i As Long
        
    With frmShip
        
        If True Then

            g_strErrorLocation = "City-Zip-State"
            strCity = QuoteTrim(m_rsOrder.Fields("f15").Value & "")
            If strCity = "" Or strCity = " " Then
               strCity = InputBox("CITY is  blank." & vbCrLf & vbCrLf _
                  & "Please enter the correct CITY.", "CITY")
            End If
              
            strZip = QuoteTrim(m_rsOrder.Fields("f17").Value & "")
            If strZip = "" Or strZip = " " Then
               strZip = InputBox(" POSTAL CODE / ZIP is  blank." & vbCrLf & vbCrLf _
                       & "Please enter the correct POSTAL CODE.", "POSTAL CODE")
            End If
              
            strState = QuoteTrim(m_rsOrder.Fields("f16").Value & "")
            If strState = "" Or strState = " " Then
               strState = InputBox("PROVINCE CODE is  blank." & vbCrLf & vbCrLf _
                          & "Please enter the *2* letter PROVINCE CODE.", "PROVINCE CODE")
            End If
           
            strPhone = Trim(m_rsOrder.Fields("f18").Value & "")
            If strPhone = "  " Or strPhone = " " Or strPhone = "" Or strPhone = "NA" Then
               strPhone = frmSetup.f183.Text
            End If
    
            .f11.Text = QuoteTrim(m_rsOrder.Fields("f11").Value & "")
            .f12.Text = QuoteTrim(m_rsOrder.Fields("f12").Value & "")
            .f13.Text = QuoteTrim(m_rsOrder.Fields("f13").Value & "")
            .f14.Text = QuoteTrim(m_rsOrder.Fields("f14").Value & "")
            .f15.Text = strCity
            .f17.Text = strZip
            .f16.Text = strState
            .f18.Text = strPhone
            .f50.Text = QuoteTrim(m_rsOrder.Fields("f50").Value & "")
            
            '** WEIGHT and PIECE COUNT
            .f116.Text = 1
            If frmSetup.chkScaleConnected = 1 Then
                .f1670.Text = ReadScale(Right(frmSetup.cmbScalePort, 1), Left(frmSetup.cboProtocol, 1))
            Else
                .f1670.Text = 1
            End If
                    '        strWeight = Cafe1.GetScaleWeight
                    '        If strWeight = "" Then
                    '            strWeight = "1"
                    '        End If
                    '        frmWgtPkg.txtWgt = strWeight
                    '        frmWgtPkg.txtPkg = "1"
                    '        Breathe
                    '        frmWgtPkg.Show
                    '        frmWgtPkg.txtPkg.SetFocus
                    '        .Count = frmWgtPkg.txtPkg
                    '        .Weight = frmWgtPkg.txtWgt
            '** WEIGHT and PIECE COUNT
             
            .f1274.Text = g_clsReg.GetRegistryValue("Carry_f1274", "")
            If .f1274.Text = "" Then .f1274.Text = "01"
            .f75.Text = "LBS"
            .f1273.Text = g_clsReg.GetRegistryValue("Carry_f1273", "")
            If .f1273.Text = "" Then .f1273.Text = "01"
            .f25.Text = QuoteTrim(m_rsOrder.Fields("CustID").Value & "")
            .f3057.Text = QuoteTrim(m_rsOrder.Fields("CustID").Value & "")
            .f1.Text = QuoteTrim(m_rsOrder.Fields("CustID").Value & "")
 
        End If
        
    End With
    
    g_strErrorLocation = "Done"

Release:
    Exit Sub
Handler:
    If Err.number = 13 Then
        Resume Next
    Else
        MsgBox Err.Description & " (GetDataToShipAddressBook)", vbSystemModal
    End If
    
    MsgBox "Error at " & g_strErrorLocation & " - " & Err.Description, , _
        "modODBC.GetDataToShipAddressBook"
    Resume Release
    Resume

End Sub
'

'---------------------------------------------------------------------------------------
' Procedure : GetDataToShipDashboard()
' DateTime  : 7/5/2004
' Purpose   : REQUIRED SUB. Called from frmShip.f1_LostFocus, which is the OrderID field.
'             Call routines needed to get data from the customer's system and assign the
'             value to the appropriate fields on the Ship form. This example uses ODBC.
'---------------------------------------------------------------------------------------
'
Public Sub GetDataToShipDashboard(strKey As String)

    On Local Error GoTo Handler

    Dim strPhone As String
    Dim strCity As String
    Dim strZip As String
    Dim strState As String
    Dim i As Long
    Dim strCode As String
    Dim strMarks As String
    Dim strDescription As String
    Dim rsQuery As String
    Dim rsCDIPart As ADODB.Recordset
    Dim rsCommodity As ADODB.Recordset
    Dim strHSCode As String
    Dim strQuantity As String
    Dim strValue As String
    Dim strCountry As String
    Dim strMID As String
    Dim strDocument1 As String
    Dim strDocument2 As String
    Dim strDocument3 As String
    Dim strCommodityID As String
    Dim strGroupCode As String
    
    With frmShip
        
        If True Then

            g_strErrorLocation = "City-Zip-State"
            strCity = QuoteTrim(m_rsOrder.Fields("SHCITY").Value & "")
            If strCity = "" Or strCity = " " Then
               strCity = InputBox("CITY is  blank." & vbCrLf & vbCrLf _
                  & "Please enter the correct CITY.", "CITY")
            End If
              
            strZip = QuoteTrim(m_rsOrder.Fields("SHPOST").Value)
            If strZip = "" Or strZip = " " Then
               strZip = InputBox(" POSTAL CODE / ZIP is  blank." & vbCrLf & vbCrLf _
                       & "Please enter the correct POSTAL CODE.", "POSTAL CODE")
            End If
              
            strState = QuoteTrim(m_rsOrder.Fields("SHPROV").Value & "")
            If strState = "" Or strState = " " Then
               strState = InputBox("PROVINCE CODE is  blank." & vbCrLf & vbCrLf _
                          & "Please enter the *2* letter PROVINCE CODE.", "PROVINCE CODE")
            End If
           
            strPhone = QuoteTrim(m_rsOrder.Fields("SHPHONE").Value & "")
            If strPhone = "  " Or strPhone = " " Or strPhone = "" Or strPhone = "NA" Then
               strPhone = frmSetup.f183.Text
            End If
    
            .f11.Text = QuoteTrim(m_rsOrder.Fields("SHCOMPANY").Value & "")
            .f12.Text = QuoteTrim(m_rsOrder.Fields("OH_ATTENTION").Value & "")
            .f13.Text = QuoteTrim(m_rsOrder.Fields("SHADD").Value & "")
            If Len(QuoteTrim(m_rsOrder.Fields("SHADD").Value & "")) > 35 Then
                .f14.Text = Mid(QuoteTrim(m_rsOrder.Fields("SHADD").Value & ""), 36, 35)
            End If
            .f15.Text = strCity
            .f17.Text = strZip
            .f16.Text = strState
            .f18.Text = strPhone
            .f50.Text = Left(QuoteTrim(m_rsOrder.Fields("SH_COUNTRY").Value & ""), 2)
            
            If Left(.f50.Text, 2) = "US" Then
                If IsNumeric(strZip) And Len(strZip) <= 5 Then
                    .f17 = Right("0000" & strZip, 5)
                ElseIf IsNumeric(strZip) And Len(strZip) <= 9 Then
                    .f17 = Right("00000000" & strZip, 9)
                End If
            End If
            
            '** WEIGHT and PIECE COUNT
            .f116.Text = 1
            If frmSetup.chkScaleConnected = 1 Then
                .f1670.Text = ReadScale(Right(frmSetup.cmbScalePort, 1), Left(frmSetup.cboProtocol, 1))
            Else
                .f1670.Text = 1
            End If
                    '        strWeight = Cafe1.GetScaleWeight
                    '        If strWeight = "" Then
                    '            strWeight = "1"
                    '        End If
                    '        frmWgtPkg.txtWgt = strWeight
                    '        frmWgtPkg.txtPkg = "1"
                    '        Breathe
                    '        frmWgtPkg.Show
                    '        frmWgtPkg.txtPkg.SetFocus
                    '        .Count = frmWgtPkg.txtPkg
                    '        .Weight = frmWgtPkg.txtWgt
            '** WEIGHT and PIECE COUNT
             
            .f1274.Text = g_clsReg.GetRegistryValue("Carry_f1274", "")
            If .f1274.Text = "" Then .f1274.Text = "92"
            .f75.Text = "LBS"
            .f1273.Text = g_clsReg.GetRegistryValue("Carry_f1273", "01")
            If .f1273.Text = "" Then .f1273.Text = "01"
            .f25.Text = QuoteTrim(m_rsOrder.Fields("OHNO").Value & "")
            .f1.Text = QuoteTrim(m_rsOrder.Fields("OHNO").Value & "")
 
            .optCommodities.Value = 1
            
            If Not m_rsExt Is Nothing Then
            If Not (m_rsExt.BOF And m_rsExt.EOF) Then
                If QuoteTrim(m_rsExt!rmaticket & "") <> "" _
                And QuoteTrim(m_rsExt!rmaticket & "") <> "NULL" Then
                    .f3056.Text = QuoteTrim(m_rsExt!rmaticket & "")
                    frmReturnLbl.f2210.Text = QuoteTrim(m_rsExt!rmaticket & "")
                    Call frmReturnLbl.AssignFormGlobalVars
                End If
                If Trim(m_rsExt!ordertypeid & "") = "3" Then
                    'For i = 0 To .f2382.UBound
                        .f2382(0).Value = 1
                    'Next
                    Call frmReturnLbl.AssignFormGlobalVars
                End If
            End If
            End If
            
            If Left(.f50.Text, 2) = "US" Then
            If Not m_rsProduct Is Nothing Then
            If Not (m_rsProduct.BOF And m_rsProduct.EOF) Then
            
                DebugPrint "DeleteIntlCommodities"
                
                Call DeleteIntlCommodities(strKey)
            
                DebugPrint "m_rsProduct"
            
                Do While Not m_rsProduct.EOF
                    
                    DebugPrint "m_rsProduct 1"
                    
                    strDescription = ""
                    Select Case UCase(QuoteTrim(m_rsProduct!IBGRCOD & ""))
                    Case "CMB"
                        strGroupCode = "NB"
                    Case "IPD"
                        strGroupCode = "TAB"
                    Case "LCD"
                        strGroupCode = "MON"
                    Case Else
                        strGroupCode = UCase(QuoteTrim(m_rsProduct!IBGRCOD & ""))
                    End Select
                    strGroupCode = ""
                    If QuoteTrim(m_rsProduct!IB_MANUF_CODE & "") <> "" Then
                        strCode = QuoteTrim(Trim(m_rsProduct!IB_MANUF_CODE) & " " & strGroupCode)
                    Else
                        strCode = strGroupCode
                    End If
                    strMarks = QuoteTrim(m_rsProduct!IB_MANUF_CODE & "")
                    strMID = ""
                    strDocument1 = ""
                    strDocument2 = ""
                    strDocument3 = ""
                    
                    strCommodityID = strCode
                    strCountry = ""
                    strHSCode = ""
                    strValue = IIf(IsNumeric(m_rsProduct!OLCOST & ""), IIf(Val(m_rsProduct!OLCOST & "") > 0, Trim(m_rsProduct!OLCOST & ""), "0"), "0")
                    strQuantity = IIf(IsNumeric(Trim(m_rsProduct!OLSHIPPED & "")), _
                                IIf(Val(Trim(m_rsProduct!OLSHIPPED & "")) > 0, _
                                Trim(m_rsProduct!OLSHIPPED & ""), "0"), "0")
                    
                    If QuoteTrim(m_rsProduct!IB_MANUF_PARTNO & "") <> "" Then
                        If Not rsCDIPart Is Nothing Then
                            If rsCDIPart.State = adStateOpen Then rsCDIPart.Close
                        Else
                            Set rsCDIPart = New ADODB.Recordset
                        End If
                        rsQuery = "SELECT * FROM CDIPartCommodity WHERE PartNumber = '" & QuoteTrim(m_rsProduct!IB_MANUF_PARTNO & "") & "'"
                        DebugPrint rsQuery
                        rsCDIPart.Open rsQuery, g_connFSMSClient, adOpenKeyset, adLockOptimistic
                        If Not rsCDIPart.BOF Then
                            If Trim(rsCDIPart!CommodityID & "") <> "" Then
                                strCode = Trim(rsCDIPart!CommodityID & "")
                            End If
                        End If
                    End If
                    
                    If Not rsCommodity Is Nothing Then
                        If rsCommodity.State = adStateOpen Then rsCommodity.Close
                    Else
                        Set rsCommodity = New ADODB.Recordset
                    End If
                    ' Set rsCommodity = Nothing
                    rsQuery = "SELECT * FROM Commodity WHERE CommodityID = '" & strCode & "'"
                    DebugPrint rsQuery
                    rsCommodity.Open rsQuery, g_connFSMSClient, adOpenKeyset, adLockOptimistic
                    
                    If Not rsCommodity.EOF Then
                        strDescription = rsCommodity("g_str79") _
                            & "; Part " & m_rsProduct!IB_MANUF_CODE _
                            & " " & strGroupCode & " " _
                            & m_rsProduct!IB_MANUF_PARTNO
                        strCommodityID = Trim(rsCommodity("CommodityID"))
                        strCode = rsCommodity("CommodityID")
                        strCountry = Trim(rsCommodity("g_str80") & "")
                        strHSCode = Digit(rsCommodity("g_str81") & "")
                        strValue = Trim(rsCommodity("g_str1030") & "")
                        strMID = Trim(rsCommodity("MID") & "")
                        strDocument1 = Trim(rsCommodity("Document1") & "")
                        strDocument2 = Trim(rsCommodity("Document2") & "")
                    End If

                    If strDescription = "" Then
                        If QuoteTrim(m_rsProduct!IB_MANUF_PARTNO & "") <> "" Then
                            strDescription = QuoteTrim(m_rsProduct!IBPARTD & "") & "; Part " & QuoteTrim(m_rsProduct!IB_MANUF_PARTNO & "") & "; "
                        Else
                            strDescription = QuoteTrim(m_rsProduct!IBPARTD & "")
                        End If
                    End If
                    
                    If strDescription & "" <> "" Then
                    
                        g_strErrorLocation = "CommodityInsert"
                        
                        DebugPrint "Insert commodity"
                        
                        Call InsertIntlCommodities(strKey, _
                            "0", _
                             strDescription, _
                             strCountry, _
                            strHSCode, _
                            strQuantity, _
                            "", _
                            "", _
                            QuoteTrim(m_rsProduct!IB_UOM & ""), _
                            strValue, _
                            Format(Val(strValue & "") _
                                    * Val(strQuantity), "0.00"), _
                             QuoteTrim(m_rsProduct!IB_MANUF_PARTNO & ""), _
                             strMarks & "", _
                             strMID, strDocument1, strDocument2, strDocument3, strCommodityID _
                            )
                    
                    End If
                    
                    g_strErrorLocation = "CommNext"
                    m_rsProduct.MoveNext
                Loop
                
            
            
            End If
            End If
            End If
            
        End If
        
    End With
    
    g_strErrorLocation = "Done"

Release:
    Exit Sub
Handler:
    If Err.number = 13 Then
        Resume Next
    Else
        MsgBox Err.Description & " (GetDataToShipDashboard)", vbSystemModal
    End If
    
    MsgBox "Error at " & g_strErrorLocation & " - " & Err.Description, , _
        "modODBC.GetDataToShipDashboard"
    Resume Release
    Resume

End Sub
'

'---------------------------------------------------------------------------------------
' Procedure : GetDataToShipDashboard()
' DateTime  : 7/5/2004
' Purpose   : REQUIRED SUB. Called from frmShip.f1_LostFocus, which is the OrderID field.
'             Call routines needed to get data from the customer's system and assign the
'             value to the appropriate fields on the Ship form. This example uses ODBC.
'---------------------------------------------------------------------------------------
'
Public Sub GetDataToShipEOL(strKey As String)

    On Local Error GoTo Handler

    Dim strPhone As String
    Dim strCity As String
    Dim strZip As String
    Dim strState As String
    Dim i As Long
        
    With frmShip
        
        If True Then

            g_strErrorLocation = "City-Zip-State"
            strCity = QuoteTrim(m_rsOrder.Fields("cCity").Value & "")
            If strCity = "" Or strCity = " " Then
               strCity = InputBox("CITY is  blank." & vbCrLf & vbCrLf _
                  & "Please enter the correct CITY.", "CITY")
            End If
              
            strZip = m_rsOrder.Fields("cPostalCode").Value
            If strZip = "" Or strZip = " " Then
               strZip = InputBox(" POSTAL CODE / ZIP is  blank." & vbCrLf & vbCrLf _
                       & "Please enter the correct POSTAL CODE.", "POSTAL CODE")
            End If
              
            strState = QuoteTrim(m_rsOrder.Fields("cState").Value & "")
            If strState = "" Or strState = " " Then
               strState = InputBox("PROVINCE CODE is  blank." & vbCrLf & vbCrLf _
                          & "Please enter the *2* letter PROVINCE CODE.", "PROVINCE CODE")
            End If
           
            strPhone = Trim(m_rsOrder.Fields("cPhoneHome").Value & "")
            If strPhone = "  " Or strPhone = " " Or strPhone = "" Or strPhone = "NA" Then
               strPhone = frmSetup.f183.Text
            End If
    
            .f11.Text = "EOL"
            .f12.Text = QuoteTrim(m_rsOrder.Fields("cFullName").Value & "")
            .f13.Text = QuoteTrim(m_rsOrder.Fields("cAddress").Value & "")
            If Len(QuoteTrim(m_rsOrder.Fields("cAddress").Value & "")) > 35 Then
                .f14.Text = Mid(QuoteTrim(m_rsOrder.Fields("cAddress").Value & ""), 36, 35)
            End If
            .f15.Text = strCity
            .f17.Text = strZip
            .f16.Text = strState
            .f18.Text = strPhone
            .f50.Text = Left(QuoteTrim(m_rsOrder.Fields("cCountry").Value & ""), 2)
            
            If Left(.f50.Text, 2) = "US" Then
                If IsNumeric(strZip) And Len(strZip) <= 5 Then
                    .f17 = Right("0000" & strZip, 5)
                ElseIf IsNumeric(strZip) And Len(strZip) <= 9 Then
                    .f17 = Right("00000000" & strZip, 9)
                End If
            End If
            
            '** WEIGHT and PIECE COUNT
            .f116.Text = 1
            If frmSetup.chkScaleConnected = 1 Then
                .f1670.Text = ReadScale(Right(frmSetup.cmbScalePort, 1), Left(frmSetup.cboProtocol, 1))
            Else
                .f1670.Text = 1
            End If
                    '        strWeight = Cafe1.GetScaleWeight
                    '        If strWeight = "" Then
                    '            strWeight = "1"
                    '        End If
                    '        frmWgtPkg.txtWgt = strWeight
                    '        frmWgtPkg.txtPkg = "1"
                    '        Breathe
                    '        frmWgtPkg.Show
                    '        frmWgtPkg.txtPkg.SetFocus
                    '        .Count = frmWgtPkg.txtPkg
                    '        .Weight = frmWgtPkg.txtWgt
            '** WEIGHT and PIECE COUNT
             
            .f1274.Text = g_clsReg.GetRegistryValue("Carry_f1274", "")
            If .f1274.Text = "" Then .f1274.Text = "92"
            .f75.Text = "LBS"
            .f1273.Text = g_clsReg.GetRegistryValue("Carry_f1273", "01")
            If .f1273.Text = "" Then .f1273.Text = "01"
            .f25.Text = Trim(m_rsOrder.Fields("cOrder_No").Value & "")
            
            ' 2011-05-06, JFW, Per Jose.
            .f3056.Text = QuoteTrim(m_rsOrder.Fields("cPONumb").Value & "")
            .f3057.Text = m_rsOrder.Fields("INVNO").Value & ""
            
            .f1.Text = QuoteTrim(m_rsOrder.Fields("OHNO").Value & "")
 
            .optCommodities.Value = 1
        
        End If
        
    End With
    
    g_strErrorLocation = "Done"

Release:
    Exit Sub
Handler:
    If Err.number = 13 Then
        Resume Next
    Else
        MsgBox Err.Description & " (GetDataToShipEOL)", vbSystemModal
    End If
    
    MsgBox "Error at " & g_strErrorLocation & " - " & Err.Description, , _
        "modODBC.GetDataToShipEOL"
    Resume Release
    Resume

End Sub
'

'---------------------------------------------------------------------------------------
' Procedure : GetDataToShipCustomer()
' DateTime  : 7/5/2004
' Purpose   : REQUIRED SUB. Called from frmShip.f1_LostFocus, which is the OrderID field.
'             Call routines needed to get data from the customer's system and assign the
'             value to the appropriate fields on the Ship form. This example uses ODBC.
'---------------------------------------------------------------------------------------
'
Public Sub GetDataToShipCustomer(strKey As String)

    On Local Error GoTo Handler

    Dim strPhone As String
    Dim strCity As String
    Dim strZip As String
    Dim strState As String
    Dim i As Long
        
    With frmShip
        
        If True Then

            g_strErrorLocation = "City-Zip-State"
            strCity = QuoteTrim(m_rsOrder.Fields("CBILCITY").Value & "")
            If strCity = "" Or strCity = " " Then
               strCity = InputBox("CITY is  blank." & vbCrLf & vbCrLf _
                  & "Please enter the correct CITY.", "CITY")
            End If
              
            strZip = QuoteTrim(m_rsOrder.Fields("CBILAREA").Value & "")
            If strZip = "" Or strZip = " " Then
               strZip = InputBox(" POSTAL CODE / ZIP is  blank." & vbCrLf & vbCrLf _
                       & "Please enter the correct POSTAL CODE.", "POSTAL CODE")
            End If
              
            strState = QuoteTrim(m_rsOrder.Fields("CBILPROV").Value & "")
            If strState = "" Or strState = " " Then
               strState = InputBox("PROVINCE CODE is  blank." & vbCrLf & vbCrLf _
                          & "Please enter the *2* letter PROVINCE CODE.", "PROVINCE CODE")
            End If
           
            strPhone = QuoteTrim(m_rsOrder.Fields("CBILTELN").Value & "")
            If strPhone = "  " Or strPhone = " " Or strPhone = "" Or strPhone = "NA" Then
               strPhone = frmSetup.f183.Text
            End If
    
            .f11.Text = QuoteTrim(m_rsOrder.Fields("COBILNAME").Value & "")
            .f12.Text = ""
            .f13.Text = QuoteTrim(m_rsOrder.Fields("CBILADDR").Value & "")
            If Len(QuoteTrim(m_rsOrder.Fields("CBILADDR").Value & "")) > 35 Then
                .f14.Text = Mid(QuoteTrim(m_rsOrder.Fields("CBILADDR").Value & ""), 36, 35)
            End If
            .f15.Text = strCity
            .f17.Text = strZip
            .f16.Text = strState
            .f18.Text = strPhone
            .f50.Text = Left(QuoteTrim(m_rsOrder.Fields("C_COUNTRY").Value & ""), 2)
            
            If Left(.f50.Text, 2) = "US" Then
                If IsNumeric(strZip) And Len(strZip) <= 5 Then
                    .f17 = Right("0000" & strZip, 5)
                ElseIf IsNumeric(strZip) And Len(strZip) <= 9 Then
                    .f17 = Right("00000000" & strZip, 9)
                End If
            End If
            
            '** WEIGHT and PIECE COUNT
            .f116.Text = 1
            If frmSetup.chkScaleConnected = 1 Then
                .f1670.Text = ReadScale(Right(frmSetup.cmbScalePort, 1), Left(frmSetup.cboProtocol, 1))
            Else
                .f1670.Text = 1
            End If
                    '        strWeight = Cafe1.GetScaleWeight
                    '        If strWeight = "" Then
                    '            strWeight = "1"
                    '        End If
                    '        frmWgtPkg.txtWgt = strWeight
                    '        frmWgtPkg.txtPkg = "1"
                    '        Breathe
                    '        frmWgtPkg.Show
                    '        frmWgtPkg.txtPkg.SetFocus
                    '        .Count = frmWgtPkg.txtPkg
                    '        .Weight = frmWgtPkg.txtWgt
            '** WEIGHT and PIECE COUNT
             
            .f1274.Text = g_clsReg.GetRegistryValue("Carry_f1274", "")
            If .f1274.Text = "" Then .f1274.Text = "01"
            .f75.Text = "LBS"
            .f1273.Text = g_clsReg.GetRegistryValue("Carry_f1273", "01")
            If .f1273.Text = "" Then .f1273.Text = "01"
            .f25.Text = QuoteTrim(m_rsOrder.Fields("CCODE").Value & "")
            
            .f1.Text = QuoteTrim(m_rsOrder.Fields("CCODE").Value & "")
 
        End If
        
    End With
    
    g_strErrorLocation = "Done"

Release:
    Exit Sub
Handler:
    If Err.number = 13 Then
        Resume Next
    Else
        MsgBox Err.Description & " (GetDataToShipCustomer)", vbSystemModal
    End If
    
    MsgBox "Error at " & g_strErrorLocation & " - " & Err.Description, , _
        "modODBC.GetDataToShipCustomer"
    Resume Release
    Resume

End Sub
'

'---------------------------------------------------------------------------------------
' Procedure : GetPickupData()
' DateTime  : 1/30/2006
' Purpose   : REQUIRED SUB. Called from frmAddTags.f1_LostFocus, which is the OrderID field.
'             Call routines needed to get data from the customer's system and assign the
'             value to the appropriate fields on the Ship form. This example uses ODBC.
'---------------------------------------------------------------------------------------
'
Public Function GetPickupData(ByVal strKey As String) As Boolean

    GetPickupData = True

End Function

'---------------------------------------------------------------------------------------
' Procedure : Initialize()
' DateTime  : 7/5/2004
' Purpose   : REQUIRED SUB. Can be used as hook to call routines to be executed on
'             program execution.
'---------------------------------------------------------------------------------------
'
Public Sub Initialize(Optional f1 As Form)
    
    Dim i As Long
    Dim frmComm As frmCommodities
    
    If f1.name = "frmDGDisclaimer" Then
        NASCAR_VERSION = "FSMSClient v800.2.2"
    End If
    
    If f1.name = "frmDGDisclaimer" Then
        If g_clsSettings.Setting("ClientDBConnection") = "" Then
        If GetSystemName <> "WINXPC9CA96EA3" Then
            ' 2014-09-01, JFW, To do via integration
            g_clsSettings.Setting("ClientDBConnection") = _
                "Driver={SQL Server};Server=ON-FEDEX-S1;Database=FSMSClientV800CA;Uid=sa;Pwd=FEDEXUSER;"
            g_clsSettings.SaveSettings
        End If
        End If
    End If
    
    If f1.name = "frmIPDAdd" Then
        If Not g_blnIPDConfirm Then
            g_frmIPDAdd.f1297.Text = Format(Now, "yyyymmdd")
        End If
    End If
    
    If f1.name = "frmReturnLbl" Then
        If frmReturnLbl.f2210.Text = "" Then
            If frmShip.f3056.Text <> "" Then
                frmReturnLbl.f2210.Text = frmShip.f3056.Text
                Call frmReturnLbl.AssignFormGlobalVars
            End If
        End If
    End If
    If f1.name = "frmShip" Then
        frmShip.f116.Enabled = False
        frmShip.lblPONumber.Caption = "RMA Number:"
    End If
    If f1.name = "frmCommodities" Then
        Set frmComm = f1
        With frmComm.grdCommodities
            For i = 0 To .Columns.Count - 1
                Select Case .Columns(i).Caption
                Case "Weight"
                    .Columns(i).Visible = False
                Case "Export Lic #"
                    .Columns(i).Visible = False
                Case "Lic Expire Date"
                    .Columns(i).Visible = False
                Case "Unit of Measure"
                    .Columns(i).Visible = False
                End Select
            Next i
            .RowHeight = 450
        End With
        frmComm.cmdClean.Visible = True
    End If
    
End Sub

' 2011-05-05, JFW, For Scapa
Public Function TDAutoCloseEnabled() As Boolean
    TDAutoCloseEnabled = False
End Function
'



'---------------------------------------------------------------------------------------
' Procedure : WriteReply()
' DateTime  : 2/14/2005
' Purpose   : REQUIRED SUB. Called after a successful ship transaction.
'             This example shows how to obtain multiple occurrence fields from the
'             FXRS reply and how to obtain multiple occurrence fields included in the
'             input transaction but not returned in the FXRS reply.
'---------------------------------------------------------------------------------------
'
Public Sub WriteReply()

    Dim strSQL As String
    Dim i As Integer
    Dim dblWeight As Double
    Dim dblDimWeight As Double
    Dim dblNetCharge As Double
    Dim strMPS As String
    Dim rsMPS As ADODB.Recordset
    
    On Local Error GoTo Handler

    If m_CNOut Is Nothing Then
        Call Connect
    End If

    g_strErrorLocation = "MPS"
    Set rsMPS = New ADODB.Recordset
    strMPS = "SELECT * FROM MPS WHERE f1 = '" & g_str1 & "' order by ShipDate"
    rsMPS.Open strMPS, g_connFSMSClient, adOpenStatic, adLockBatchOptimistic
    i = 1
    If Not rsMPS.EOF Then
        Do Until rsMPS.EOF
            If g_str1274 = "18" Then
                If IsNumeric(rsMPS!g_str1670) Then
                    dblWeight = CDbl(rsMPS!g_str1670)
                Else
                    dblWeight = 0
                End If
                ' If Left(frmShip.f75.Text, 3) = "LBS" Then dblWeight = dblWeight * 0.454
                If IsNumeric(rsMPS!g_str57) _
                And IsNumeric(rsMPS!g_str58) _
                And IsNumeric(rsMPS!g_str59) Then
                    dblDimWeight = CLng(rsMPS!g_str57) * CLng(rsMPS!g_str58) * CLng(rsMPS!g_str59)
                End If
                dblDimWeight = dblDimWeight / 166
                If Left(frmShip.f75.Text, 3) = "KGS" Then dblDimWeight = dblDimWeight / (2.54 * 2.54 * 2.54)
                If dblWeight < dblDimWeight Then dblWeight = dblDimWeight
                If Left(frmShip.f75.Text, 3) = "LBS" Then dblWeight = dblWeight * 0.454
                dblNetCharge = dblWeight * 1.01
                If i = 1 Then dblNetCharge = dblNetCharge + 7.1
                dblNetCharge = dblNetCharge * (1 + g_dblFuelRate)
    
                Call frmShip.g_clsParser.SetTag("37-" & i, CStr(Round(dblNetCharge * 100)))
            End If ' IPD
            
            Call frmShip.g_clsParser.SetTag("25-" & i, rsMPS!g_str25)
            
            rsMPS.MoveNext
            i = i + 1
        Loop
    End If
    
    For i = 1 To frmShip.g_clsParser.TagCount(29)
    
        If frmShip.g_clsParser.Tag(25, i) <> "" Then
            g_str25 = frmShip.g_clsParser.Tag(25, i)
        End If
        
        strSQL = ""
        If GetSystemName = "WINXPC9CA96EA3" And 0 <> InStr(1, LCase(frmShip.cboLocationName(0).Text), "jdh") Then
            If g_str25 <> "" Then
            If IsNumeric(g_str25) Then
                strSQL = strSQL & "INSERT INTO [FedExCDI].[dbo].[OrderTrackingTable] "
                strSQL = strSQL & "([OrderNo], [TrackingNo], [date_time], [Carrier], [NetCost]) "
                strSQL = strSQL & "Values "
                ' orno, track, datetime, "FEDEX", freight
                strSQL = strSQL & "(%1, '%2', '%DateTime', 'FEDEX', %3) "
             
                strSQL = Replace(strSQL, "%1", g_str25)
                strSQL = Replace(strSQL, "%2", frmShip.g_clsParser.Tag(29, i))
                
                If IsNumeric(frmShip.g_clsParser.Tag(37, i)) Then
                    strSQL = Replace(strSQL, "%3", Round(CDbl(frmShip.g_clsParser.Tag(37, i)) / 100, 2))
                ElseIf i = 1 Then
                    If g_str1274 = "18" And IsNumeric(m_str37) Then
                        strSQL = Replace(strSQL, "%3", Round(CDbl(m_str37) / 100, 2))
                    ElseIf IsNumeric(g_str37) Then
                        strSQL = Replace(strSQL, "%3", Round(CDbl(g_str37) / 100, 2))
                    Else
                        strSQL = Replace(strSQL, "%3", 0)
                    End If
                Else
                    strSQL = Replace(strSQL, "%3", 0)
                End If
                If IsDate(g_str24) Then
                    strSQL = Replace(strSQL, "%DateTime", Format(CDate(g_str24) + TimeValue(Now), "yyyy-mm-dd HH:nn:ss"))
                ElseIf IsNumeric(g_str24) Then
                    strSQL = Replace(strSQL, "%DateTime", Format(g_str24, "0000-00-00") & " " & Format(Now, "HH:nn:ss"))
                Else
                    strSQL = Replace(strSQL, "%DateTime", Format(Now, "yyyy-mm-dd HH:nn:ss"))
                End If
                    
            End If
            End If
        
        ElseIf GetSystemName = "WINXPC9CA96EA3" And 0 <> InStr(1, LCase(frmShip.cboLocationName(0).Text), "eol") Then
            If g_str25 <> "" Then
            If IsNumeric(g_str25) Then
                strSQL = strSQL & "INSERT INTO [FedExCDI].[dbo].[OrderEOLTrackingTable] "
                strSQL = strSQL & "([OrderNo], [TrackingNo], [date_time], [Carrier], [NetCost]) "
                strSQL = strSQL & "Values "
                ' orno, track, datetime, "FEDEX", freight
                strSQL = strSQL & "(%1, '%2', '%DateTime', 'FEDEX', %3) "
             
                strSQL = Replace(strSQL, "%1", g_str25)
                strSQL = Replace(strSQL, "%2", frmShip.g_clsParser.Tag(29, i))
                
                If IsNumeric(frmShip.g_clsParser.Tag(37, i)) Then
                    strSQL = Replace(strSQL, "%3", Round(CDbl(frmShip.g_clsParser.Tag(37, i)) / 100, 2))
                ElseIf i = 1 Then
                    If g_str1274 = "18" And IsNumeric(m_str37) Then
                        strSQL = Replace(strSQL, "%3", Round(CDbl(m_str37) / 100, 2))
                    ElseIf IsNumeric(g_str37) Then
                        strSQL = Replace(strSQL, "%3", Round(CDbl(g_str37) / 100, 2))
                    Else
                        strSQL = Replace(strSQL, "%3", 0)
                    End If
                Else
                    strSQL = Replace(strSQL, "%3", 0)
                End If
                If IsDate(g_str24) Then
                    strSQL = Replace(strSQL, "%DateTime", Format(CDate(g_str24) + TimeValue(Now), "yyyy-mm-dd HH:nn:ss"))
                ElseIf IsNumeric(g_str24) Then
                    strSQL = Replace(strSQL, "%DateTime", Format(g_str24, "0000-00-00") & " " & Format(Now, "HH:nn:ss"))
                Else
                    strSQL = Replace(strSQL, "%DateTime", Format(Now, "yyyy-mm-dd HH:nn:ss"))
                End If
                    
            End If
            End If
        
        ElseIf GetSystemName = "WINXPC9CA96EA3" Then
            If frmShip.f1.Visible = True Then
                Call frmShip.SaveAddress(frmShip.f1)
            End If
        
        ElseIf 0 <> InStr(1, LCase(frmShip.cboLocationName(0).Text), "jdh") Then
            If g_str25 <> "" Then
            If IsNumeric(g_str25) Then
                strSQL = strSQL & "INSERT INTO %database.[dbo].[OrderTrackingTable] "
                strSQL = strSQL & "([OrderNo], [TrackingNo], [date_time], [Carrier], [NetCost]) "
                strSQL = strSQL & "Values "
                ' orno, track, datetime, "FEDEX", freight
                strSQL = strSQL & "(%1, '%2', '%DateTime', 'FEDEX', %3) "
             
                strSQL = Replace(strSQL, "%1", g_str25)
                strSQL = Replace(strSQL, "%2", frmShip.g_clsParser.Tag(29, i))
                
                If IsNumeric(frmShip.g_clsParser.Tag(37, i)) Then
                    strSQL = Replace(strSQL, "%3", Round(CDbl(frmShip.g_clsParser.Tag(37, i)) / 100, 2))
                ElseIf i = 1 Then
                    If g_str1274 = "18" And IsNumeric(m_str37) Then
                        strSQL = Replace(strSQL, "%3", Round(CDbl(m_str37) / 100, 2))
                    ElseIf IsNumeric(g_str37) Then
                        strSQL = Replace(strSQL, "%3", Round(CDbl(g_str37) / 100, 2))
                    Else
                        strSQL = Replace(strSQL, "%3", 0)
                    End If
                Else
                    strSQL = Replace(strSQL, "%3", 0)
                End If
                If IsDate(g_str24) Then
                    strSQL = Replace(strSQL, "%DateTime", Format(CDate(g_str24) + TimeValue(Now), "yyyy-mm-dd HH:nn:ss"))
                ElseIf IsNumeric(g_str24) Then
                    strSQL = Replace(strSQL, "%DateTime", Format(g_str24, "0000-00-00") & " " & Format(Now, "HH:nn:ss"))
                Else
                    strSQL = Replace(strSQL, "%DateTime", Format(Now, "yyyy-mm-dd HH:nn:ss"))
                End If
                    
            End If
            End If
        ElseIf 0 <> InStr(1, LCase(frmShip.cboLocationName(0).Text), "eol") Then
            If g_str25 <> "" Then
            If IsNumeric(g_str25) Then
                strSQL = strSQL & "INSERT INTO %database.[dbo].[OrderEOLTrackingTable] "
                strSQL = strSQL & "([OrderNo], [TrackingNo], [date_time], [Carrier], [NetCost]) "
                strSQL = strSQL & "Values "
                ' orno, track, datetime, "FEDEX", freight
                strSQL = strSQL & "(%1, '%2', '%DateTime', 'FEDEX', %3) "
             
                strSQL = Replace(strSQL, "%1", g_str25)
                strSQL = Replace(strSQL, "%2", frmShip.g_clsParser.Tag(29, i))
                
                If IsNumeric(frmShip.g_clsParser.Tag(37, i)) Then
                    strSQL = Replace(strSQL, "%3", Round(CDbl(frmShip.g_clsParser.Tag(37, i)) / 100, 2))
                ElseIf i = 1 Then
                    If g_str1274 = "18" And IsNumeric(m_str37) Then
                        strSQL = Replace(strSQL, "%3", Round(CDbl(m_str37) / 100, 2))
                    ElseIf IsNumeric(g_str37) Then
                        strSQL = Replace(strSQL, "%3", Round(CDbl(g_str37) / 100, 2))
                    Else
                        strSQL = Replace(strSQL, "%3", 0)
                    End If
                Else
                    strSQL = Replace(strSQL, "%3", 0)
                End If
                If IsDate(g_str24) Then
                    strSQL = Replace(strSQL, "%DateTime", Format(CDate(g_str24) + TimeValue(Now), "yyyy-mm-dd HH:nn:ss"))
                ElseIf IsNumeric(g_str24) Then
                    strSQL = Replace(strSQL, "%DateTime", Format(g_str24, "0000-00-00") & " " & Format(Now, "HH:nn:ss"))
                Else
                    strSQL = Replace(strSQL, "%DateTime", Format(Now, "yyyy-mm-dd HH:nn:ss"))
                End If
                    
            End If
            End If
        
        ElseIf True Then
        
        End If
        
        strSQL = Replace(strSQL, "%database", g_clsSettings.Setting("CDIDatabase"))
        
        If strSQL <> "" Then
            DebugPrint strSQL
            m_CNOut.Execute strSQL
        End If
    Next i
    
    m_str37 = ""
    'g_strErrorLocation = "Done"

Release:
    Exit Sub

Handler:
    MsgBox "Error, " & Err.Description, , "modODBC.WriteReply"
    'Call Kill
    Resume Release


End Sub
'---------------------------------------------------------------------------------------
' Procedure : WriteReturnReply()
' DateTime  : 7/14/2005
' Purpose   : REQUIRED SUB. Called after a successful return label transaction.
'             This is called for both regular and online return labels.
'---------------------------------------------------------------------------------------
'
Public Sub WriteReturnReply()

    DebugPrint "WriteReturnReply"

End Sub
'---------------------------------------------------------------------------------------
' Procedure : WriteBOLReply()
' DateTime  : 1/11/2006
' Purpose   : REQUIRED SUB. Called after a successful FedEx Freight BOL transaction.
'             This is called for both regular and online return labels.
'---------------------------------------------------------------------------------------
'
Public Sub WriteBOLReply()

End Sub
'---------------------------------------------------------------------------------------
' Procedure : WriteBatchEditReply()
' DateTime  : 1/17/2006
' Purpose   : REQUIRED SUB. Called after a successful Batch Error Edit transaction.
'             This is called for both regular and online return labels.
'---------------------------------------------------------------------------------------
'
Public Sub WriteBatchEditReply()

End Sub
' Procedure : WriteTagReply()
' DateTime  : 1/26/2006
' Purpose   : REQUIRED SUB. Called after a successful Call Tag/Express Tag transaction.
'---------------------------------------------------------------------------------------
'
Public Sub WriteTagReply()

End Sub
' Procedure : WriteCancelTagReply()
' DateTime  : 1/26/2006
' Purpose   : REQUIRED SUB. Called after a successful Cancel Call Tag/Express Tag transaction.
'---------------------------------------------------------------------------------------
'
Public Sub WriteCancelTagReply()

End Sub
'---------------------------------------------------------------------------------------
' Procedure : WriteReturnDelete()
' DateTime  : 7/14/2005
' Purpose   : REQUIRED SUB. Called after a successful return label delete transaction.
'             This is called for both regular and online return labels.
'---------------------------------------------------------------------------------------
'
Public Sub WriteReturnDelete(ByVal strTracking As String)

End Sub
'---------------------------------------------------------------------------------------
' Procedure : WriteError()
' DateTime  : 7/5/2004
' Purpose   : REQUIRED SUB. Can be used as hook to call routines to be executed after
'             an FXRS Error reply transaction.
'---------------------------------------------------------------------------------------
'
Public Sub WriteError()
    MsgBox "Shipping Error: " & g_str3, vbCritical, "FSMS Error"
End Sub
'---------------------------------------------------------------------------------------
' Procedure : WriteDelete()
' DateTime  : 7/5/2004
' Purpose   : REQUIRED SUB. Can be used as hook to call routines to be executed after
'             successful FXRS Delete.
' Called    : frmShip g_clsParser_Parsecomplete() event on FSMS 123 reply
'---------------------------------------------------------------------------------------
'
Public Sub WriteDelete(ByVal strTracking As String)

End Sub

#End If



